package controllers

import (
	"gcopyright/repositories"
	"gcopyright/service"
)

type solcontroller struct {
	Common
}

func NewSolcontroller() *solcontroller {
	return &solcontroller{}
}

func (s *solcontroller) GetHash() {
	sol := service.NewSolService(s.Ctx)
	s.Common.ReturnSuccess(sol.QuerQuXiaoGang())
}

func (s *solcontroller) GetDeploy() { // 部署
	hash := s.Ctx.URLParam("hash")
	sql := repositories.NewRepositoriesSqlite()
	sol := service.NewSolService(s.Ctx)
	info := sql.QuernFileInfoTableAllElement(hash)
	deployAddress := sol.Deploy(1, hash, info, sql)
	s.Common.ReturnSuccess(deployAddress)
}
func (s *solcontroller) GetBlock() {
	sol := service.NewSolService(s.Ctx)
	s.Common.ReturnSuccess(sol.BlockNumber())
}

func (s *solcontroller) GetCode() {
	//sol := service.NewSolService(s.Ctx)
	s.Common.ReturnSuccess("eth.getCode('0x0000000...')")
}

func (s *solcontroller) GetNewAccount() { //创建新用户，并插入accounts_table
	sol := service.NewSolService(s.Ctx)
	sql := repositories.NewRepositoriesSqlite()
	sol.NewAccount("0x0003", sql)
	s.Common.ReturnSuccess("eth.NewAccount()")
}

func (s *solcontroller) GetAccounts() { //获取用户列表，不包含admin
	sol := service.NewSolService(s.Ctx)
	s.Common.ReturnSuccess(sol.Accounts())
}

func (s *solcontroller) GetTest() {
	sol := service.NewSolService(s.Ctx)
	s.Common.ReturnSuccess(sol.Ls())
}
